<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of rice
 *
 * @author BENZPIPE
 */
    class rice{
        private $rvID;
        private $database;
        private $riceTable;
        
        public function __construct($rvID="") {
            if($rvID!=""){
                $this->rvID=$rvID;
            }
            require_once dirname(__FILE__)."/../lib/database.inc.php";
            require_once dirname(__FILE__)."/../function/config.php";
            $this->riceTable=RICE_VARIETY_TABLE;
            $dbObj=new database;
            $this->database=$dbObj->connect();
                    
            $args = func_get_args();
            if(count($args)==1){
                $this->setRvID($args[0]);
            }
        }

        private function setRvID($rvID){
            $this->rvID=$rvID;
        }
        public function getRvID(){
            return $this->rvID;
        }
        
        function search($keyword=""){
            $query="
                select      *
                from        $this->riceTable
                where       rvName like '%$keyword%' or
                            rvType like '%$keyword%' or
                            rvHistory like '%$keyword%' or
                            rvCertified like '%$keyword%' or
                            rvCharacteristic like '%$keyword%' or
                            rvProduct like '%$keyword%' or
                            rvDominant like '%$keyword%' or
                            rvCaution like '%$keyword%' or
                            rvArea like '%$keyword%' or
                            rvDiseaseResistance like '%$keyword%' or
                            rvInsectResistance like '%$keyword%' or
                            rvSusceptibleDeisease like '%$keyword%' or
                            rvSusceptibleInsect like '%$keyword%' or
                            rvSensitivity like '%$keyword%'
                order by    rvName
                ";
            $result=  $this->database->query($query);
            while($row=$result->fetch_array(MYSQLI_ASSOC)){
                $temp[$row["rvID"]]=$row;
            }
            return $temp;
        }

        function getRice(){
            $query="
                select  *
                from    $this->riceTable
                where   rvID='".$this->rvID."'
                ";
            $result=  $this->database->query($query);
            $row=  $result->fetch_array(MYSQLI_ASSOC);
            return $row;
        }
    }
 